/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ie.nell;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 *
 * @author stw
 */
public class EventDBOpenHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 2;
    public static final String EVENT_TABLE_NAME = "event";
    public static final String URL_TABLE_NAME = "url";
    public static final String EVENT_TYPE = "type";
    public static final String URL_TYPE = "type"; // url or title
    public static final String URL_ID = "url_id";
    public static final String TIME = "time";
    private static final String EVENT_TABLE_CREATE =
                "CREATE TABLE " + EVENT_TABLE_NAME + " (" +
                " event_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                " type INT, " +
                " x INT, " +
                " y INT, " +
                " x_doc INT, " +
                " y_doc INT, " +
                " url INT, " +
                " time TIMESTAMP DEFAULT (DATETIME('now')));";

        private static final String URL_TABLE_CREATE =
                "CREATE TABLE " + URL_TABLE_NAME + " (" +
                URL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                " url TEXT, " +
                URL_TYPE + " TEXT, " +
                " time TIMESTAMP DEFAULT (DATETIME('now')));";

    EventDBOpenHelper(Context context) {
        super(context, "events", null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(EVENT_TABLE_CREATE);
        db.execSQL(URL_TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public void recreateAllTables(SQLiteDatabase db){
        db.execSQL("DROP TABLE IF EXISTS " + EVENT_TABLE_NAME +";");
        db.execSQL("DROP TABLE IF EXISTS " + URL_TABLE_NAME +";");
        db.execSQL(EVENT_TABLE_CREATE);
        db.execSQL(URL_TABLE_CREATE);
        
    }
}
